package org.samith.scheduler;

import java.util.Calendar;

import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.ejb.Timeout;
import javax.ejb.Timer;
import javax.ejb.TimerService;

@Stateless
public class BillPaymentEmailNotifier implements IBillPaymentNotify {

	@Resource
	TimerService timerService;
	
	private static String TIMER_NAME = "BillPaymentNotifier";
	
	@Override
	public void startScanDueBillPaymentUsers() {
		System.out.println("Starting "+TIMER_NAME+" Sheduler.........");
		Calendar cal = Calendar.getInstance();
		long interval = 100 * 1000;
		timerService.createTimer(cal.getTime(), interval, TIMER_NAME);
	}

	@Timeout
	public void findUsersForSendingBillingNotifications(Timer timer) {
		System.out.println("Executing "+TIMER_NAME+" Sheduler.");
	}

	public void cancelScanDueBillPaymentUsers() {
		for (Object obj : timerService.getTimers()) {
			Timer timer = (Timer) obj;
			if (timer.getInfo().equals(TIMER_NAME))
				timer.cancel();
		}
	}
}
